function(my_add_glib_marshal marshal_file output_prefix)
    # 处理输入文件
    get_filename_component(marshal_filename "${marshal_file}" NAME_WE)
    
    # 生成目标文件路径
    set(marshal_header "${CMAKE_CURRENT_BINARY_DIR}/${output_prefix}-marshal.h")
    set(marshal_source "${CMAKE_CURRENT_BINARY_DIR}/${output_prefix}-marshal.c")

    # 检查输入文件是否存在
    if (NOT EXISTS "${marshal_file}")
        message(FATAL_ERROR "Marshal file ${marshal_file} does not exist.")
    endif()

    # 生成 .h 文件
    add_custom_command(
        OUTPUT ${marshal_header}
        COMMAND glib-genmarshal --header ${marshal_file} > ${marshal_header}
        DEPENDS ${marshal_file}
        COMMENT "Generating marshal header: ${marshal_header}"
    )

    # 生成 .c 文件
    add_custom_command(
        OUTPUT ${marshal_source}
        COMMAND glib-genmarshal --body ${marshal_file} > ${marshal_source}
        DEPENDS ${marshal_file}
        COMMENT "Generating marshal source: ${marshal_source}"
    )

    # 提供生成的目标供调用者使用
    set(${output_prefix}_MARSHAL_HEADER ${marshal_header} PARENT_SCOPE)
    set(${output_prefix}_MARSHAL_SOURCE ${marshal_source} PARENT_SCOPE)
endfunction()
